Repository navigation
Respect caller capacity in refcount IP sockaddr writeback - #659
Merged
nunoplopes merged 1 commit intoNov 19, 2026
Merged
Conversation
nunoplopes
reviewed
Nov 19, 2026
| let l = ::libc::sockaddr_in::from(*ss.as_sockaddr_in().unwrap()); | ||
| out.reinterpret_cast::<SockaddrIn>() | ||
| .write(SockaddrIn::from_libc(&l)); | ||
| let mut bytes = [0; 16]; |
Contributor
There was a problem hiding this comment.
Instead of using constants, can you use a sizeof expression here?
Contributor
Author
There was a problem hiding this comment.
Both address buffers now use sizeof expressions for their corresponding native libc address types instead of numeric sizes. The bounded-copy logic and fixtures are unchanged.
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
perfloop
Bot
force-pushed
the
perfloop-pr-open-6pgf6jamzw
branch
from
November 19, 2026 10:18
e9a7a41 to
16278a8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refcount
getsocknamenow copies at most the caller's advertised buffer capacity for IPv4 and IPv6 addresses instead of writing a full address struct or panicking on short buffers. Previously, callinggetsocknamewith a capacity below 16 or 28 bytes overwrote destination bytes past the caller's limit or panicked reading a fullSockaddrInorSockaddrIn6when the destination allocation was physically smaller.Sockaddr::encodeinrules/socket/shim.rsnow serializesSockaddrInorSockaddrIn6into a local buffer sized with::std::mem::size_offor the corresponding nativelibcaddress type, reads the inputout_len, and copies onlymin(out_len, address_bytes.len())bytes when non-zero throughPtr::<u8>::with_slice_mut, leaving any suffix and zero-capacity null destinations untouched before writingss.len()toout_len.getpeernameandrecvfrominherit the same bounded IP writeback.tests/unit/socket_ip_name.cchecks unbound IPv4 and IPv6 datagram sockets across capacities0,1,2,actual - 1,actual, andactual + 1on both padded buffers and exact-size heap allocations, comparing prefixes against native output and asserting untouched suffixes. On the base revision with only the new fixture files added,socket_ip_name.cfails in refcount while passing in native C and unsafe.Returned IP address length reporting (
ss.len()), syscall error branches,Sockaddr::decode, and the Unix branch are unchanged. Testing ran on Linux; macOS CI handles macOS validation.Testing
libcc2rsreinterpreted-pointer unit tests report 5 passed, 0 failed, and 0 ignored (73 filtered out).Scoped
litsocket unit tests (ifaddrs.c,inet_pton_ntop.c,libc_struct_without_default.cpp,netdb.c,socket_ip_name.c,socket_listen.c,socket_open_close.c,socket_transparent_union.c,socket_type_constants.c,socket_unix_name.c,sockopt.c) in Linux Release report 11 passed, 0 failed, and 0 skipped.clang-format-23,cargo fmt, andcargo clippyonrulesandlibcc2rspassed with no warnings or formatting changes.Full
tests/unit,tests/std,tests/ub,tests/multi-file,libcc2rs-macros, and macOS builds are left to target CI.Case and evidence
Made by Perfloop. Human sponsor: Tomás Senart.